import {
    reqAddressList,
    reqDeleteUser
} from '../../api/index'
Page({
    data: {
        addressArr: [], //存储全部收件人地址
    },
    //每一次页面出现的时候都获取一次地址列表的数据
    onShow() {
        //获取地址列表
        this.getUserAddress();
    },
    async getUserAddress() {
        const result = await reqAddressList();
        if (result.code == 200) {
            this.setData({
                addressArr: result.data
            })
        }
    },
    //点击标记图标进行页面跳转
    edit(event) {
        const id = event.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/address/add/add?id=${id}`,
        })
    },
    //点击删除图标
    async deleteUser(event) {
        const id = event.currentTarget.dataset.id;
        const result = await reqDeleteUser(id);
        if(result.code==200){
            //再次获取全部收件人地址
            this.getUserAddress();
        }
    }
})